#!/usr/bin/ruby
$:.unshift File.join(File.dirname(__FILE__))

require 'basic_configuration'
require 'aws_context'
require 'fib-client'
require 'allocator'

#  Allocates a server, connects a fib client to it,
#    and fetches a stream of fibonacci numbers.

port = 20808

config = BasicConfiguration.new
aws_bucket = config.aws[:aws_bucket]
if aws_bucket.nil?
  puts "Bucket must be set: define AWS_BUCKET in environment or config file."
  exit 1
end


alloc = Allocator.new(aws_bucket, "active-set/fib-instances", "fib-work")
public_dns = alloc.new_client
if public_dns.nil? 
   puts "no servers are running, try again in a minute"
   exit 1
end

f = FibClient.new(public_dns, port)
Signal.trap("INT") do
  f.shutdown
end

f.run
